import { Button, Space, Table, Layout } from 'myselfantd';
import type { ColumnsType, TableProps } from 'antd/es/table';
import React, { useState, useEffect, useMemo, useCallback } from 'react';
import { getMachineAlarmInfoList } from '../api';
interface DataType {
  code: string;
  name: string;
  type: number;
  machineNames: string;
  time: string;
  status: number;
  remark: string;
}

const App = (props: any) => {
  return (
    <>
      <h2>{props.params.machineName} 报警详情</h2>
      <Layout.PageContent
        table={useMemo(
          () => ({
            template: [
              {
                title: '编号',
                dataIndex: 'code',
                key: 'code',
                width: 120,
              },
              {
                title: '围栏名称',
                dataIndex: 'name',
                key: 'name',
                width: 120,
                showSorterTooltip: false,
              },
              {
                title: '报警类型',
                dataIndex: 'type',
                key: 'type',
                showSorterTooltip: false,
                width: 120,
                render: (_, record) => {
                  enum Type {
                    '进入报警',
                    '退出报警',
                  }
                  return <Space size="middle">{Type[_]}</Space>;
                },
              },
              {
                title: '约束时间',
                // sorter: true,
                key: 'time',
                render: (_, record) => (
                  <Space size="middle">{_.startTime + ' - ' + _.endTime}</Space>
                ),
              },
            ] as ColumnsType<DataType>,
            data: {
              data: [] as ColumnsType<DataType>,
              page: { total: 0, pageSize: 20, current: 1 },
            },
          }),
          [],
        )}
        request={useCallback(async (page: any, params: any) => {
          let defaultParams: any = {
            pageIndex: 1,
            pageSize: 10,
            code: props.params.code,
            taskId: props.params.taskId,
          };
          let {
            result = [],
            pageIndex = page.current,
            pageSize = page.pageSize,
          } = await getMachineAlarmInfoList({ ...defaultParams, ...params });
          return {
            data: result,
            page: { total: result.length, pageSize: pageSize, current: pageIndex },
          };
        }, [])}
      />
    </>
  );
};

export default App;
